package com.demo.modules.mq.rabbit.service.topic;

import com.demo.modules.mq.rabbit.RabbitAnnouncementMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息生产者
 *
 * @author Rog
 */
@Slf4j
@Component
public class RabbitTopicMessageProducerService {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 发送到topic交换机
     *
     * @param routKet
     */
    public void topicQueue(String routKet) {
        String exeChange = "wr.topic";
        //发送的消息
        RabbitAnnouncementMessage rabbitAnnouncementMessage = new RabbitAnnouncementMessage();
        rabbitAnnouncementMessage.setId("1");
        rabbitAnnouncementMessage.setContent("helle,tow queue");
        //指定key，对应交换器的过滤字符
        rabbitTemplate.convertAndSend(exeChange, routKet, rabbitAnnouncementMessage);
    }
}

